import util from "./util/Util.js";
var btnsContrl = {
	subBtnArr: [{
			act: "pay_recoder",
			sort: 31,
			fontIcon: 'icon-fukuanjilu',
			title: "付款记录",
		},
		{
			act: "op_recoder",
			sort: 30,
			fontIcon: 'icon-caozuojilu',
			title: "操作记录",
		},
	],
	thBtnArr: [{
			act: "reject",
			sort: 2,
			fontIcon: 'jvjuetuihuo',
			title: "拒绝退货",
		},
		{
			act: "agree",
			sort: 1,
			fontIcon: "icon-tongyituihuo",
			title: "同意退货",
		},
	],

	returnRecord: {
		act: "return_record",
		sort: 29,
		fontIcon: 'icon-caozuojilu',
		title: "退货记录",
	},

	print: {
		sort: 4.1,
		fontIcon: 'icon-dayin',
		title: "打印",
		act: 'print'
	},
	return_ck: {
		sort: 4.3,
		title: "退货",
		fontIcon: 'icon-tuihuo',
		act: 'return_ck'
	},
	copy: {
		sort: 4.2,
		fontIcon: 'icon-chaodan',
		title: "抄单",
		act: 'copy'
	},

	fontIcon: {
		scrap: "icon-zuofei", //作废
		tock: "icon-queren", //确认
		del: "icon-shanchu", //删除
		edt3: "icon-bianji", //编辑
		store_in: "icon-ruku", //入库
		store_out: "icon-chuku", //出库
		pay_out: "icon-tuikuan", //退款
	},
	//操作代码，可选值：unlock（解锁）、del（删除）、tock（确认）、store_out（销售出库）、store_in（退货入库）、scrap作废
}

/***单据按钮数据处理逻辑****/
btnsContrl.btnsOrderHandler = function (data) {
	if (data) {
		let arr = [];
		let btnArr = [];
		let obj = data.status_act.acts;
		for (let i in obj) {
			let o = obj[i];

			//暂时不显示
			if (o.act == "custom_add" || o.act == "store_in" || o.act == "supp_add") continue;


			o.fontIcon = this.fontIcon[i];
			arr.push(o);
		}
		let t = data.type;
		if (data.ch == 2) {
			t = 0;
			if (data.ask_rt && data.ask_rt.status_act && data.ask_rt.status_act.acts) {
				let o = data.ask_rt.status_act.acts;
				if (o.edt && o.edt.act == 'edt') {
					//已经退货通过的云单,修改理由
					btnArr.push(o.edt);
					return btnArr;
				}
				if (o.tock && o.tock.act == 'tock') {
					//申请退货的云店单
					btnArr = this.thBtnArr;
					return btnArr;
				}
			} else {
				if (data.status > 1 && data.type != 4) {
					//过滤已确认和已作废的云单（小程序）
					t = 1;
				}
			}
		}
		btnArr = this.getBtnsArr(arr, t, data.type);
		return btnArr;
	}
}

btnsContrl.getBtnsArr = function (arr, type, oType) {
	console.log('123===.',type, oType);
	if (type == 4 || oType == 4) {
		let ary = [this.subBtnArr[1]];
		arr = arr.concat(ary);
	} else {
		if (type != 3)
			arr = arr.concat(this.subBtnArr);
	}

	if (type == 1) {
		arr.push(this.print);
		arr.push(this.return_ck);
		arr.push(this.copy);
		arr.push(this.returnRecord);
	} else if (type == 2) {
		arr.push(this.print);
		arr.push(this.copy);
	} else if (type == 0 && oType == 1) //云单
	{
		arr.push(this.print);
	}
	util.sort(arr);
	return arr;
}

/***服务预约单据按钮数据处理逻辑****/
btnsContrl.btnsYYOrderHandler = function (data) {
	if (data) {
		let arr = [];
		let btnArr = [];
		let obj = data.status_act.acts;
		for (let i in obj) {
			let o = obj[i];

			//暂时不显示
			if (o.act == "custom_add" || o.act == "store_in" || o.act == "supp_add") continue;

			// if(o.act == "tobook")continue; //预约隐藏，打开只要删除这行代码

			o.fontIcon = this.fontIcon[i];
			arr.push(o);
		}
		let t = data.type;
		if (data.ch == 2) {
			t = 0;
			if (data.ask_rt && data.ask_rt.status_act && data.ask_rt.status_act.acts) {
				let o = data.ask_rt.status_act.acts;
				// if (o.edt && o.edt.act == 'edt') {
				// 	//已经退货通过的云单,修改理由
				// 	btnArr.push(o.edt);
				// 	return btnArr;
				// }
				if (o.tock && o.tock.act == 'tock') {
					//申请退货的云店单
					btnArr = this.thBtnArr;
					return btnArr;
				}
			} else {
				if (data.status > 1 && data.type != 4) {
					//过滤已确认和已作废的云单（小程序）
					t = 1;
				}
			}
		}
		btnArr = this.getYYBtnsArr(arr, t, data.type);
		return btnArr;
	}
}

btnsContrl.getYYBtnsArr = function (arr, type, oType) {
	console.log('123===.',type, oType);
	if (type == 4 || oType == 4) {
		let ary = [this.subBtnArr[1]];
		arr = arr.concat(ary);
	} else {
		if (type != 3)
			arr = arr.concat(this.subBtnArr);
	}

	if (type == 1) {
		arr.push(this.print);
		arr.push(this.copy);  //抄单隐藏，放开注释就可以了
	} else if (type == 2) {
		arr.push(this.print);
		arr.push(this.copy);//抄单隐藏，放开注释就可以了
	} else if (type == 0 && oType == 1) //云单
	{
		arr.push(this.print);
	}
	util.sort(arr);
	return arr;
}

export default btnsContrl;